import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/15 8:58
 * @description O(n^2)应该会超时, 实测没有超时，勉强通过
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int smallestDistancePair(int[] nums, int k) {
        int[] arr = new int[(int)1e6+1];
        for(int i=0 ; i<nums.length; i++){
            for(int j = i+1; j < nums.length; j++){
                int diff = Math.abs(nums[i]-nums[j]);
                arr[diff]++;
            }
        }
        int count = 0;
        for(int i = 0; i < arr.length; i++){
            while(arr[i]!=0){
                arr[i]--;
                count++;
                if(count==k){
                    return i;
                }
            }
        }
        return 0;
    }
}
